package com.szq.day39.dao;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.szq.day39.entity.Blog;
@Repository
public class BlogDAO {
	@Resource
	private SessionFactory sf;
	
	public List<Blog> findAll() throws Exception{
		return sf.getCurrentSession().createQuery("from Blog b order by b.createTime desc", Blog.class).getResultList();
	}
	
	public Blog findById(int id) throws Exception{
		return sf.getCurrentSession().get(Blog.class, id);
	}
	
	public void save(Blog blog) throws Exception{
		sf.getCurrentSession().save(blog);
	}
	
	public void delete(Blog blog) throws Exception{
		sf.getCurrentSession().delete(blog);
	}
	
	public void update(Blog blog) throws Exception{
		sf.getCurrentSession().update(blog);
	}

}
